#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
using namespace std;
const int N = 5010;
int f[N][N], c[N], fc[N];
int n;
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> c[i];
    vector<int> v;
    v.push_back(1), fc[1] = c[1];
    for (int i = 2; i <= n; i++)
    {
        if (c[i] != c[i - 1])
        {
            v.push_back(i);
            fc[v.size()] = c[i];
        }
    }
    n = v.size();
    for (int len = 2; len <= n; len++)
    {
        for (int l = 1; l + len - 1 <= n; l++)
        {
            int r = l + len - 1;
            if (fc[l] == fc[r] && l < r - 1) f[l][r] = f[l + 1][r - 1] + 1;
            else f[l][r] = min(f[l + 1][r], f[l][r - 1]) + 1;
        }
    }
    cout << f[1][n] << endl;
}